#include "LookUp_real32_TU8_U16.h"
#include "BINARYSEARCH_U16.h"
#include "rtwtypes.h"

void LookUp_real32_TU8_U16(real32_T *pY, const uint8_T *pYData, uint16_T u,
  const uint16_T *pUData, uint32_T iHi)
{
  uint32_T iLeft;
  uint32_T iRght;
  BINARYSEARCH_U16( &(iLeft), &(iRght), u, pUData, iHi);

  {
    real_T lambda;
    if (pUData[iRght] > pUData[iLeft] ) {
      uint16_T num;
      uint16_T den;
      den = pUData[iRght];
      den = (uint16_T)((uint32_T)den - pUData[iLeft]);
      num = u;
      num = (uint16_T)((uint32_T)num - pUData[iLeft]);
      lambda = (real_T)num / (real_T)den;
    } else {
      lambda = 0.0;
    }

    {
      real_T yLeftCast;
      real_T yRghtCast;
      yLeftCast = pYData[iLeft];
      yRghtCast = pYData[iRght];
      yLeftCast += lambda * ( yRghtCast - yLeftCast );
      (*pY) = (real32_T)yLeftCast;
    }
  }
}
